<?php

function detectMobileVerion() {
	
		 $ci =& get_instance();
    	$ci->load->model('public_model');		
		$mobiledomainname = $ci->public_model->getSystemParameterValue("mobiledomainname"); 
		if(!empty($mobiledomainname)) {
			$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone") || strpos($_SERVER['HTTP_USER_AGENT'],"iPod") || strpos($_SERVER['HTTP_USER_AGENT'],"Android");
			$mobileURL = $mobiledomainname ;
			$currentURL = getAddress() ;	
			$isMobileUrl = strpos($currentURL,$mobileURL);	
			if ($browser == true && $isMobileUrl === false )  {	
				header('Location: '. $mobileURL);
				exit;
			}
		}
}

function isAccessFromMobile() {
	
		 $ci =& get_instance();
    	//$ci->load->model('public_model');
    	$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone") || strpos($_SERVER['HTTP_USER_AGENT'],"iPod") || strpos($_SERVER['HTTP_USER_AGENT'],"Android"); 
		if ($browser == true && $ci->config->item('fullsize')==0 )  {	
			return true;
		}		
//		$mobiledomainname = $ci->public_model->getSystemParameterValue("mobiledomainname"); 
//		if(!empty($mobiledomainname)) {
//		$browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone") || strpos($_SERVER['HTTP_USER_AGENT'],"iPod") || strpos($_SERVER['HTTP_USER_AGENT'],"Android"); 
//		if ($browser == true  )  {	
//			return true;
//		}
//		$mobileURL = $mobiledomainname ;
//		$currentURL = getAddress() ;	
//		$isMobileUrl = strpos($currentURL,$mobileURL);
		
//		if($isMobileUrl) {
//			return true ;
//		}
	//}
	
	
	//return false;
	 
}

function getAddress()
 {
    /*** check for https ***/
    $protocol = isset($_SERVER['HTTPS'])?($_SERVER['HTTPS'] == 'on' ? 'https': 'http'): 'http';
    /*** return the full address ***/
    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 }

function GetDomain($url)
{
    $nowww = ereg_replace('www\.','',$url);
	$domain = parse_url($nowww);
	if(!empty($domain["host"]))
    {
     	return $domain["host"];
     } else
     {
     	return $domain["path"];
     } 
}


?>